<?php
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
*/

session_start();
include ('includes/includes.php');

?>


 <?php
    connect();

    $pregunta = $_GET['preg'];
    $matricula = $_GET['matricula'];
    $res1 = $_SESSION['p1_al1'];
    $res2 = $_SESSION['p1_al2'];
    $res3 = $_SESSION['p1_al3'];
    $anyescolar = $_GET['anyescolar'];
    $nivell = $_GET['nivell'];

    $sql_str = "INSERT INTO sociograma (matricula , nivell , cursescolar , pregunta , ordre, res1 , hora) VALUES ( '{$matricula}', '{$nivell}', '{$anyescolar}', {$pregunta}, 1, '{$res1}', CURRENT_TIMESTAMP )";
    $result = mysql_query($sql_str) OR die(mysql_error());
    
    $sql_str = "INSERT INTO sociograma (matricula , nivell , cursescolar , pregunta , ordre, res1 , hora) VALUES ( '{$matricula}', '{$nivell}', '{$anyescolar}', {$pregunta}, 2, '{$res2}', CURRENT_TIMESTAMP )";
    $result = mysql_query($sql_str) OR die(mysql_error());

    $sql_str = "INSERT INTO sociograma (matricula , nivell , cursescolar , pregunta , ordre, res1 , hora) VALUES ( '{$matricula}', '{$nivell}', '{$anyescolar}', {$pregunta}, 3, '{$res3}', CURRENT_TIMESTAMP )";
    $result = mysql_query($sql_str) OR die(mysql_error());

    $db_close = @mysql_close($db);
    
    $_SESSION['p1_al1'] = "";
    $_SESSION['p1_al2'] = "";
    $_SESSION['p1_al3'] = "";
    $seg_preg = $pregunta + 1;
    if ($seg_preg<7){
        $reload = "socio_preg.php?id={$matricula}&nivell={$nivell}&cursescolar={$anyescolar}&preg={$seg_preg}";
    } else {
        $reload = "sociograma_final.php?id={$matricula}";    
    }
    

    header("Location: ". $reload);
    exit;

?>
